package com.glsc.ngateway.common.base.domain.mysql.gateway.oaflow;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import com.glsc.ngateway.common.base.domain.mysql.BaseEntity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLDeleteAll;
import org.hibernate.annotations.Where;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Index;
import javax.persistence.Table;
import java.time.LocalDateTime;

/**
 * oa同步自研网关记录实体类
 *
 * @author xuchang
 */
@EqualsAndHashCode(callSuper = true)
@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
@Entity
@Where(clause = "deleted = 0")
@SQLDelete(sql = "update t_oa_flow_subscribe_oa_flow_info set deleted = UNIX_TIMESTAMP(NOW()), handled = 0 where id=?")
@SQLDeleteAll(sql = "update t_oa_flow_subscribe_oa_flow_info set deleted = UNIX_TIMESTAMP(NOW()), handled = 0 where id=?")
@Table(name = "t_oa_flow_subscribe_oa_flow_info", indexes = {
        @Index(name = "UK_REQUEST_ID", columnList = "request_id, deleted", unique = true)})
public class TOaFlowSubscribeOaFlowInfo extends BaseEntity {
    private static final long serialVersionUID = -2758136986172189360L;

    @Column(name = "request_id", columnDefinition = "bigint(255) not null comment '同步id'")
    private Integer requestId;

    @Column(name = "last_update_time", columnDefinition = "datetime comment '最后一次更新时间'")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    protected LocalDateTime lastUpdateTime;

    @Column(name = "current_node_type", columnDefinition = "varchar(16) comment '当前节点类型'")
    private String currentNodeType;

    @Column(name = "status", columnDefinition = "varchar(512) comment 'oa流程状态'")
    private String status;

}
